<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<%
	String path = request.getContextPath() + "/";
	String basePath = request.getScheme() + "://"
			+ request.getServerName() + ":" + request.getServerPort()
			+ path;
%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/functions" prefix="fn"%>
<style>
.text-right {
	text-align: right;
}
</style>
<head>
  <base href="<%=basePath%>">
  <meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<!-- Bootstrap 3.3.6 -->
  <link rel="stylesheet" href="css/bootstrap.css">
  <link rel="stylesheet" href="dist/css/AdminLTE.min.css">
  <link rel="stylesheet" href="dist/css/skins/_all-skins.min.css">
  <title>朗读亭-数据备份</title>
  <!-- Tell the browser to be responsive to screen width -->
  <meta content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no" name="viewport">
 
</head>
<body class="hold-transition skin-blue sidebar-mini">
<div class="wrapper" style="width:100%;">

    <!-- Main content -->
    <section class="content">
      <!-- Info boxes -->
      
      <!-- /.row -->


          <!-- TABLE: LATEST ORDERS -->
          <div class="box box-info" style="width:100%;">
            <div class="box-header with-border">
              <h3 class="box-title">数据库管理</h3>

              <div class="box-tools pull-right">
              <a class="btn btn-primary" href="javascript:bf()" target="_blank">数据库备份</a>
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                </button>
                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
              </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <div class="box-content">
						<table class="table table-striped table-bordered bootstrap-datatable datatable">
						  <thead>
							  <tr>
								  <th>序号</th>
								  <th>文件名</th>				
								  <th>操作</th>
							  </tr>
						  </thead>   
						  <tbody id = "show">
						  
							
							
						  </tbody>
					  </table>            
					</div>
				</div><!--/span-->
			</div><!--/row-->
							
							 <div class="box box-info" style="width:100%;">
            <div class="box-header with-border">
              <h3 class="box-title">本地数据库文件上传</h3>

              <div class="box-tools pull-right">
                <button type="button" class="btn btn-box-tool" data-widget="collapse"><i class="fa fa-minus"></i>
                </button>
                <button type="button" class="btn btn-box-tool" data-widget="remove"><i class="fa fa-times"></i></button>
              </div>
            </div>
            <!-- /.box-header -->
            <div class="box-body">
              <div class="box-content">
						<br>
							<form action="<%=basePath%>Systems/fileUpload" method="post" enctype="multipart/form-data">
	                             <input type="file" name="filename" id="filename"><br>
	                                   <input type="submit" value="确定">
                                              </form>
							</div>
							<div class="tab-pane" id="custom">

							</div>
							<div class="tab-pane" id="messages">

							</div>
						  
							
							
						  </tbody>
					  </table>            
					</div>
				</div><!--/span-->
			</div><!--/row-->
							
					
              
              
		
		                       
	<div class="modal" id="sqlbackup">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">×</button>
					<h3>数据库备份</h3>
				</div>
				<div class="modal-body">

					<table class="table table-bordered table-striped table-condensed">
						<tbody>
							<tr>
								<td class="center">备份文件名</td>
								<td class="center"><input type="text" style="color:black;" maxLength="10"
									name="filename1" id="filename1"></td>

							</tr>
						</tbody>
					</table>

				</div>
				<div class="modal-footer">
					<a href="#" class="btn" data-dismiss="modal">退出</a>
					<button href="#" class="btn btn-primary" onclick="backup();"
						data-dismiss="modal" id="bfbtn">确定</button>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->
	<!-- 备份加载页面 -->
	<div class="col-md-3 modal" id="bfloading">
          <div class="box box-info box-solid">
            <div class="box-header">
              <h3 class="box-title">备份中。。</h3>
            </div>
            <div class="box-body">
                                                数据库正在备份中，请稍后...
            </div>
            <!-- /.box-body -->
            <!-- Loading (remove the following to stop the loading)-->
            <div class="overlay">
              <i class="fa fa-refresh fa-spin"></i>
            </div>
            <!-- end loading -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
	<!-- 还原加载页面 -->
	<div class="col-md-3 modal" id="hyloading">
          <div class="box box-info box-solid">
            <div class="box-header">
              <h3 class="box-title">还原中。。</h3>
            </div>
            <div class="box-body">
                                                数据库正在还原中，请稍后...
            </div>
            <!-- /.box-body -->
            <!-- Loading (remove the following to stop the loading)-->
            <div class="overlay">
              <i class="fa fa-refresh fa-spin"></i>
            </div>
            <!-- end loading -->
          </div>
          <!-- /.box -->
        </div>
        <!-- /.col -->
      </div>
      <!-- /.row -->
	<!-- 下载文件到本地 -->
	<div class="modal" id="downl_file">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">×</button>
					<h3>文件名：</h3>
				</div>

				<div class="modal-body">
					<p>你确定要下载吗？</p>

				</div>
				<div class="modal-footer">
					<a href="#" class="btn" data-dismiss="modal">退出</a> <a
						href="<%=basePath%>Systems/download?filen=1"
						class="btn btn-primary">确定下载</a>
				</div>


			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->
	<!-- 删除文件 -->
	<div class="modal" id="del_file">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">×</button>
					<h3>文件名：</h3>
				</div>

				<div class="modal-body">
					<p>你确定要删除？</p>
				</div>
				<div class="modal-footer">
					<a href="#" class="btn" data-dismiss="modal">退出</a> <a
						href="<%=basePath%>Systems/del_file?filen=1"
						class="btn btn-primary">确定删除</a>
				</div>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- 本地数据库文件上传 -->
	<div class="modal" id="sqlupload1">
		<div class="modal-dialog">
			<div class="modal-content">
				<div class="modal-header">
					<button type="button" class="close" data-dismiss="modal">×</button>
					<h3>本地数据库文件上传</h3>
				</div>

				<form action="<%=basePath%>Systems/fileUpload" method="post">
					<div class="modal-body">

						<table class="table table-bordered table-striped table-condensed">
							<tbody>
								<tr>
									<td class="center">请选择本地数据库文件</td>
								</tr>
								<tr>
									<td class="center"><input type="file" name="filename"><br>
									</td>

								</tr>
							</tbody>
						</table>
					</div>
					<div class="modal-footer">
						<a href="#" class="btn" data-dismiss="modal">退出</a>
						<button class="btn btn-primary" type="submit">确定</button>
					</div>
				</form>
			</div>
			<!-- /.modal-content -->
		</div>
		<!-- /.modal-dialog -->
	</div>
	<!-- /.modal -->




	<!-- /.box -->
        </div>
        <!-- /.col -->

         </div>
      <!-- /.row -->
    </section>
    <!-- /.content -->
  </div>
  <!-- /.content-wrapper -->

  


<!-- ./wrapper -->

<script src="js/jquery-1.9.1.js"></script>
<script src="js/bootstrap.js"></script>
<script src="dist/js/app.min.js"></script>
<script type="text/javascript" src="js/layer/layer.js"></script>
<script>
$(function openpage(){
	GetFileInfo();
});
function GetFileInfo(){
	var strurl="<%=basePath%>Systems/filelist";
	$.ajax({
        type: "POST",
        url: strurl,
        success: function (data) {
        	var strtext="<tbody id = \"show\">";
        	for ( var id in data.result) {
        		var strFileNub = data.result[id].id+1;
        		var strFileName = data.result[id].name;	
        		strtext+="<tr><td>"+strFileNub+"</td>"+
        				"<td>"+strFileName+"</td>"+
						"<td class='center'>"+
							"<a class='btn btn-success' href=\"javascript:load('"+strFileName+"')\">"+
								"<i class='icon-zoom-in icon-white'></i>数据库还原</a>"+ 
							"<a class='btn btn-info'  href=\"javascript:download('"+strFileName+"')\">"+
								"<i class=\"icon-edit icon-white\"></i>下载文件到本地  </a>"+
							"<a class=\"btn  btn-danger\" href=\"javascript:DelfileInfo('"+strFileName+"')\">"+
								"<i class=\"icon-trash icon-white\"></i>删除</a></td></tr>"	
        	}
        	strtext+="</tbody>";
     //   	alert(strtext);
			$("#show").replaceWith(strtext);
        }
	})
}
//备份
function bf()
{
   $('#sqlbackup').modal('show');
}
function backup()
{
	var filen =document.getElementById('filename1').value;
  	var strurl='<%=basePath%>Systems/backup?filen=' + filen;
  	if(filen.length==0){
	  	 layer.msg("备份失败，请填写备份文件名称 ");
   		 location.reload();
  	}else{
	  	$('#bfloading').modal('show');
  		$.ajax({
	        type: "POST",
	        async : true,
	        url: strurl,
	        success: function (data) { 	
		        if (data == "ok") {
		        	$("#bfloading").modal('hide');
		        	layer.msg('备份成功！');
		        }else if(data == "nopms"){
		        	layer.msg("需要管理员权限");
		       	}else {
		        	$("#bfloading").modal('hide');
		        	layer.msg("备份失败，请重新备份！");
		        }
	        	setTimeout(location.reload(),2000);
	        }
	    });
	}
}


//还原
function load(v){
 	var filen =v;
  	var strurl='<%=basePath%>Systems/load?filen=' + filen;
  
   	if(filen.length==0){
	   	layer.msg("还原失败了，请 重试！ ");
    	parent.location.reload();
 	 }else{  
 		$("#hyloading").modal('show');
  		$.ajax({
	  		async : true,
	        type: "POST",
	        url: strurl,
	        success: function (data) {
		        if (data == "ok") {
		        	$("#hyloading").modal('hide');
		        	layer.msg('还原 成功！');
		        }else {
		        	$("#hyloading").modal('hide');
		        	layer.msg("还原失败，请 重试！");
		        }
		        setTimeout(location.reload(),2000);
	         }
     	 });
 	 }
}

//删除
function DelfileInfo(i)
{
   var strname = i;
      
   $('#del_file h3').html("备份文件名:"+strname);
   $('#del_file a:last').attr("href","<%=basePath%>Systems/del_file?filen="+strname);
   $('#del_file').modal('show');
}


//下载文件
function download(i)
{
   var strname = i;
      
   $('#downl_file h3').html("备份文件名:"+strname);
   $('#downl_file a:last').attr("href","<%=basePath%>Systems/download?filen="+strname);
   $('#downl_file').modal('show');
}

//上传文件
</script>
</body>
</html>
